package com.crm.base.controller;

import com.crm.base.service.ProductService;
import com.crm.common.pojo.Product;
import com.crm.global.exception.ExceptionEnum;
import com.crm.global.result.Message;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
@Api(tags = "产品信息")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name = "page",defaultValue = "1",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(value = "页面大小",name = "size",defaultValue = "1",required = true,dataType = "int",paramType = "query")
    })
    @ApiOperation("查询所有的产品信息")
    @PostMapping("/findAll")
    public ResponseEntity<Message<PageInfo<Product>>> findAll(int page, int size, @RequestBody(required = false) Product product) {
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS,productService.findAll(page,size,product)));
    }
}